//---------------------------------------------------------------------------
#ifndef DocumentH
#define DocumentH
//---------------------------------------------------------------------------
#include <Printers.hpp>
#include <dbtables.hpp>
#include <math.h>
#include <eic.h>

#ifdef _MYSQL
  #include "ZConnect.hpp"
  #include "ZMySqlCon.hpp"
  #include "ZMySqlQuery.hpp"
  #include "ZMySqlTr.hpp"
  #include "ZQuery.hpp"
  #include "ZTransact.hpp"
  #include "ZMySqlQuery.hpp"
#endif
//---------------------------------------------------------------------------
#include "uEtat.h"
#include "uDessin.h"
#include "uFormules.h"

enum eTypeSQL{
   eParadox,
   eFirebird,
  #ifdef _MYSQL
   eMYSQL
  #endif
   };


#define CanvasCALCUL_NB_PAGES      ((TCanvas*)-1)
#define CanvasIMPRIME_DS_VIDE      ((TCanvas*)-3)
#define CanvasIMPRIME_DS_VIDE_EMF  ((TCanvas*)-2)
#define CanvasIMPRIME_STOP         ((TCanvas*)-4)
#define HAUTEUR_ENTRE_BANDES     3
typedef unsigned __int64 ULONG64_PTR;
typedef ULONG64_PTR DWORD64_PTR;

#define MAKEINT64( a, b) ((::LONG64)(((DWORD)((DWORD64_PTR)(a) & 0xffffffff)) | ((DWORD64)((DWORD)((DWORD64_PTR)(b) & 0xffffffff))) << 32))
#define LODWORD(l)           ((DWORD)((DWORD64_PTR)(l) & 0xffffffff))
#define HIDWORD(l)           ((DWORD)((DWORD64_PTR)(l) >> 32))

#define MAKE_NIVEAUBANDE( NiveauBande, TypeBande) MAKELONG(NiveauBande,(WORD)TypeBande)
#define MAKE_ETATNIVEAUBANDE( NiveauEtat, NiveauBande, TypeBande) MAKEINT64( MAKE_NIVEAUBANDE(NiveauBande,TypeBande), NiveauEtat)

#define GET_NIVETAT( EtatNiveauType)                       HIDWORD( EtatNiveauType)
#define GET_NIVBANDE( EtatNiveauType)                      LOWORD(LODWORD( EtatNiveauType))
#define GET_TYPBANDE( EtatNiveauType)                      (TYPE_BANDE)HIWORD(LODWORD( EtatNiveauType))

class TEtat;
class TBande;
class TListOfBandes;
//---------------------------------------------------------------------------


class TDocument;
class TCpChamp;
class TCpTableau;
typedef bool __fastcall (__closure *TOnDocEventInterne  )       ( TDocument  *Doc);
typedef bool __fastcall (__closure *TOnEtatEventInterne )       ( TEtat      *Etat);
typedef bool __fastcall (__closure *TOnSQLParamsEventInterne)   ( TEtat      *Etat, TParams *SQLParams);
typedef bool __fastcall (__closure *TOnBandeEventInterne)       ( TBande     *Bande);
typedef void __fastcall (__closure *TOnConstBandeEventInterne)  ( const TBande     *Bande);
typedef bool __fastcall (__closure *TOnChampEventInterne)       ( TCpChamp   *Champ);
typedef bool __fastcall (__closure *TOnTableauEventInterne)     ( TCpTableau *Tableau);
typedef TEtat* __fastcall (__closure *TOnGetEtatEnDessous)      (TEtat* CurEtat);



class ETATAPI TDocument : public TObject
{
    friend class TEtat;
protected :
    EICFont        *m_FontDefaut;
    enum TColor     m_ColorDefaut;
    EICCurrencyFmt *m_FormatCurDefaut;
    EICNumberFmt   *m_FormatNumDefaut;

    void   __fastcall SetFontDefaut( EICFont *font)    { if( *m_FontDefaut != *font) { m_FontDefaut->Assign( font); Modifie(); };};
    void   __fastcall SetColorDefaut( TColor Color)    { if( m_ColorDefaut != Color) { m_ColorDefaut = Color;       Modifie(); };};
    void   __fastcall SetFormatCurDefaut( EICCurrencyFmt *f) {  if( m_FormatCurDefaut != f)
                                                               {
                                                                    if( m_FormatCurDefaut)
                                                                        m_FormatCurDefaut = new EICCurrencyFmt( f->CurrencyFmt);
                                                                    else
                                                                        m_FormatCurDefaut->Assign( *f);
                                                                    Modifie();
                                                               }
                                                            };
    void   __fastcall SetFormatNumDefaut( EICNumberFmt *f)  {  if( m_FormatNumDefaut != f)
                                                               {
                                                                    if( m_FormatNumDefaut)
                                                                        m_FormatNumDefaut = new EICNumberFmt( f->NumberFmt);
                                                                    else
                                                                        m_FormatNumDefaut->Assign( *f);
                                                                    Modifie();
                                                               }
                                                            };
private :
    int         m_Numero;
    AnsiString  m_File;
    DWORD       m_FileVersion;
    AnsiString  m_Titre;
    TCoordonnee m_HauteurDoc;
    TCoordonnee m_LargeurDoc;
    TCoorRect   m_Marges, m_crTmp;
    TCoordonnee m_MargeHorsEntete;
    TCoordonnee m_MargeHorsPied;
    TCoordonnee m_MargeHorzCp;
    TCoordonnee m_MargeVertCp;
    EICListStyle *m_Styles;

    int             m_TypePapier;

      // Définition globale d'un document
    TListOfBandes  *m_LstBandes;
    TList          *m_ListeEtat;
    TStrings       *m_ListTitre;
    bool           m_bListTitreADetruire;
    TStringList    *m_ColorPerso;
    byte           m_NbLangues;
    byte           m_NbMiseEnForme;

    bool         m_bModified;
    bool         m_bEnCoursDestruction;
    TObject     *m_Support;
    HRGN         m_RGNInvalide, m_hClip;
    MyCBarre    *m_Barre;
    bool         m_CpEndsInPied;

    void __fastcall InitVar(const AnsiString &File, TCanvas *CanvasSupport, TStrings *ListTitre);
    void   __fastcall SetTitre( const AnsiString &s)   { if( m_Titre   != s)         {m_Titre = s;          Modifie();} };
    void   __fastcall SetHauteur( const TCoordonnee &Hauteur) { if( m_HauteurDoc != Hauteur)   {m_HauteurDoc  = Hauteur; _Invalidate(); Modifie();} };
    void   __fastcall SetLargeur( const TCoordonnee &Largeur) { if( m_LargeurDoc != Largeur)   {m_LargeurDoc  = Largeur; _Invalidate(); Modifie();} };
    const TCoorRect&  __fastcall GetMarges( );
    void   __fastcall SetMarges(  const TCoorRect &Marges) { if( m_Marges  != Marges)    {m_Marges   = Marges;  _Invalidate(); Modifie();} };
    void   __fastcall SetMargeHorzCp( const TCoordonnee &MargeHorzCp) { if( m_MargeHorzCp != MargeHorzCp) { m_MargeHorzCp  = MargeHorzCp; _Invalidate(); Modifie();} };
    void   __fastcall SetMargeVertCp( const TCoordonnee &MargeVertCp) { if( m_MargeVertCp != MargeVertCp) { m_MargeVertCp  = MargeVertCp; _Invalidate(); Modifie();} };
    void   __fastcall SetMargeHorsEntete( const TCoordonnee &MargeHorsEntete) { if( m_MargeHorsEntete != MargeHorsEntete) { m_MargeHorsEntete  = MargeHorsEntete; _Invalidate(); Modifie();} };
    void   __fastcall SetMargeHorsPied( const TCoordonnee &MargeHorsPied)     { if( m_MargeHorsPied   != MargeHorsPied)   { m_MargeHorsPied    = MargeHorsPied;   _Invalidate(); Modifie();} };
    void   __fastcall SetTypePapier( int Type)         { if( m_TypePapier != Type)   {m_TypePapier = Type;  _Invalidate(); Modifie();} };
    int    __fastcall GetNbEtat( )            { return( m_ListeEtat->Count); };

public :
    __fastcall TDocument( const AnsiString &File, TCanvas *CanvasSupport=NULL, TStrings *ListeEtat=NULL, const AnsiString &TitreEtatVoulu = EmptyStr);
    virtual __fastcall ~TDocument();
    void __fastcall Assign( const TDocument *Doc);
    void __fastcall Modifie();
    void __fastcall FixeNonModifie();
    void __fastcall Enregistre();
    void __fastcall Calculs();
    void __fastcall Draw( );
    void __fastcall Draw( TObject* Support, TEtat *Etat = NULL);
    TEtat* __fastcall AjouteEtat( const TCoordonnee &c, const AnsiString& Titre = EmptyStr);
    TEtat* __fastcall AjouteEtat( const TEtat* Etat, unsigned long Tag = NO_TAG);
    void __fastcall ExchangeEtat( int n, int n1);
    void __fastcall DeplaceEtat( int Orig, int Vers);
    void __fastcall SupprimeEtat( const TEtat* e);
    int  __fastcall IndexOf( const TEtat* e)const { return m_ListeEtat->IndexOf( (void*)e);}
    TEtat* __fastcall GetEtat( const AnsiString& s)const;
    TEtat* __fastcall GetEtat( int i)const;

    TBande* __fastcall SearchBande( TYPE_BANDE Type);
    void __fastcall InsereBande( TYPE_BANDE Type);
    void __fastcall SupprimeBande( TYPE_BANDE Type);
    void __fastcall InsereEnteteDoc( )    { InsereBande( e_EnTete);};
    void __fastcall InserePiedDoc( )      { InsereBande( e_Pied);};
    void __fastcall SupprimeEnteteDoc( )  { SupprimeBande( e_EnTete);};
    void __fastcall SupprimePiedDoc( )    { SupprimeBande( e_Pied);};
    __property TListOfBandes* LstBandes = {read = m_LstBandes};

    void __fastcall ScrollBasBitmap( const TCoordonnee &YOrigine, const TCoordonnee &YOffset, Graphics::TBitmap* BmpSupport);
    void __fastcall ChangeSupport( TObject* Support, bool bForceRefresh = false);
    bool __fastcall IsValidSupport( )const;
    TCanvas* __fastcall IsCanvasSupport( )const;


    __property   TObject*     Support         = { read=m_Support};
    __property   int          Numero          = { read=m_Numero, write=m_Numero};
    __property   bool         bEnCoursDestruction = { read=m_bEnCoursDestruction};
    __property   bool         Modified        = { read=m_bModified};
    __property   DWORD        FileVersion     = { read=m_FileVersion};
    __property   AnsiString   File            = { read=m_File,              write=m_File};
    __property   AnsiString   Titre           = { read=m_Titre,             write=SetTitre};
    __property   TCoordonnee  Hauteur         = { read=m_HauteurDoc,        write=SetHauteur};
    __property   TCoordonnee  Largeur         = { read=m_LargeurDoc,        write=SetLargeur};
    __property   TCoordonnee  MargeHorzCp     = { read=m_MargeHorzCp,       write=SetMargeHorzCp};
    __property   TCoordonnee  MargeVertCp     = { read=m_MargeVertCp,       write=SetMargeVertCp};
    __property   TCoordonnee  MargeHorsEntete     = { read=m_MargeHorsEntete,       write=SetMargeHorsEntete};
    __property   TCoordonnee  MargeHorsPied       = { read=m_MargeHorsPied,         write=SetMargeHorsPied};
    __property   const TCoorRect    Marges          = { read=GetMarges,           write=SetMarges};
    __property   const TCoorRect    MargesReelles   = { read=m_Marges};
    __property   int                TypePapier      = { read=m_TypePapier,        write=SetTypePapier};
    __property   EICFont            *FontDefaut      = { read=m_FontDefaut,        write=SetFontDefaut};
    __property   TColor             ColorDefaut     = { read=m_ColorDefaut,       write=SetColorDefaut};
    __property   EICCurrencyFmt     *FormatCurDefaut = { read=m_FormatCurDefaut, write=SetFormatCurDefaut};
    __property   EICNumberFmt       *FormatNumDefaut  = { read=m_FormatNumDefaut,  write=SetFormatNumDefaut};
    __property   TStringList        *ColorPerso = { read=m_ColorPerso};
    __property   TStrings           *ListTitre = { read=m_ListTitre};
    __property   byte               NbLangues = { read=m_NbLangues};
    __property   EICListStyle       *Styles   = { read=m_Styles};
    __property   bool               CpEndsInPied = { read=m_CpEndsInPied, write=m_CpEndsInPied};

    void __fastcall SupprimeLangue( byte IdLangue);
    void __fastcall AjouteLangue();

    __property   TEtat*      CurEtat     = { read=m_EtatEnCours};
    __property   int         NbEtats     = { read=GetNbEtat};
    __property   MyCBarre*   Barre       = { read=m_Barre, write=m_Barre};


    __property   HRGN        RGNInvalide   = { read=m_RGNInvalide     };

    void __fastcall _Invalidate(const HRGN  h);
    void __fastcall _Invalidate(const TRect &rc);
    void __fastcall _Invalidate();
    void __fastcall _Invalidate(const int Left, const int Top, const int Right, const int Bottom);
    void __fastcall ValidateAll( );
    HRGN __fastcall GetRegionInvalideInRect_ClipIt( const TRect &rc);
    HRGN __fastcall GetRegionInvalideInRect_ClipIt( const RECT  &rc);
    bool __fastcall IsRectInvalideInClip( const RECT  &rc);
    void __fastcall EffaceRegion( HRGN h);
    AnsiString __fastcall GetTruePathOfFile( const AnsiString &File);
    bool __fastcall AImprimer();


    // Evènements
private :
    TNotifyEvent                f_OnDebutPage;
    TNotifyEvent                f_OnFinPage;
    TOnDocEventInterne          f_OnDebutDoc;
    TOnEtatEventInterne         f_OnDebutEtat;
    TOnSQLParamsEventInterne    f_OnSQLParams;
    TOnEtatEventInterne         f_OnBDInitialized;
    TOnBandeEventInterne        f_OnFirstBandeEtat;
    TOnBandeEventInterne        f_OnBande;
    TOnConstBandeEventInterne   f_OnAfterFirstBandeInit;
    TOnChampEventInterne        f_OnChamp;
    TOnTableauEventInterne      f_OnTableau;
    TOnEtatEventInterne         f_OnFinEtat;
    TOnDocEventInterne          f_OnFinDoc;
    TOnErrorEvent               f_OnError;
    TOnVariableEvent            f_OnVariable;
    TOnGetEtatEnDessous         f_OnGetEtatEnDessous;
    bool                        m_bInterruption;
    TEtat*                      m_EtatEnCours;
    byte                        m_Langue;
public  :
    void __fastcall Nettoie( );

    __property TNotifyEvent             OnDebutPage     = { read=f_OnDebutPage,     write=f_OnDebutPage};
    __property TNotifyEvent             OnFinPage       = { read=f_OnFinPage,       write=f_OnFinPage};
    __property TOnDocEventInterne       OnDebutDoc      = { read=f_OnDebutDoc,      write=f_OnDebutDoc};
    __property TOnEtatEventInterne      OnDebutEtat     = { read=f_OnDebutEtat,     write=f_OnDebutEtat};
    __property TOnSQLParamsEventInterne OnSQLParams     = { read=f_OnSQLParams,     write=f_OnSQLParams};
    __property TOnEtatEventInterne      OnBDInitialized = { read=f_OnBDInitialized, write=f_OnBDInitialized};
    __property TOnBandeEventInterne     OnFirstBandeEtat = { read=f_OnFirstBandeEtat, write=f_OnFirstBandeEtat};
    __property TOnBandeEventInterne     OnBande         = { read=f_OnBande,         write=f_OnBande};
    __property TOnConstBandeEventInterne OnAfterFirstBandeInit= { read=f_OnAfterFirstBandeInit,write=f_OnAfterFirstBandeInit};
    __property TOnChampEventInterne     OnChamp         = { read=f_OnChamp,         write=f_OnChamp};
    __property TOnTableauEventInterne   OnTableau       = { read=f_OnTableau,       write=f_OnTableau};
    __property TOnEtatEventInterne      OnFinEtat       = { read=f_OnFinEtat,       write=f_OnFinEtat};
    __property TOnDocEventInterne       OnFinDoc        = { read=f_OnFinDoc,        write=f_OnFinDoc};
    __property TOnErrorEvent            OnError         = { read=f_OnError,         write=f_OnError};
    __property TOnVariableEvent         OnVariable      = { read=f_OnVariable,      write=f_OnVariable};
    __property TOnGetEtatEnDessous      OnGetEtatEnDessous  = { read=f_OnGetEtatEnDessous,      write=f_OnGetEtatEnDessous};
    __property bool                     bInterruption   = { read=m_bInterruption};
    __property TEtat*                   EtatEnCours     = { read=m_EtatEnCours,     write=m_EtatEnCours};
    __property byte                     Langue          = { read=m_Langue,          write=m_Langue};
};

//---------------------------------------------------------------------------
class  TMyObject : public TObject
{

private :
//    TDocument    *m_Owner;
    HRGN         __fastcall GetInvalideRgn()const  {return DocOwner->RGNInvalide; };
    //TEtat*       GetCurEtat()const           {return m_Owner->CurEtat;     };
    virtual TDocument* __fastcall  GetDocOwner()const=0;
    TCoordonnee  __fastcall GetLargBarreGauche()const;

public  :
    __fastcall TMyObject( ):TObject(){};


    virtual void __fastcall Draw()=0;
    virtual void __fastcall Enregistre( TFlux *f)const=0;
    virtual void __fastcall Nettoie( )=0;
    virtual void __fastcall Calculs()=0;
//    virtual bool __fastcall Proprietes( );
    __property   TDocument   *DocOwner         = { read=GetDocOwner};//{ read=m_Owner,      write=m_Owner  };
//    __property   TEtat       *CurEtat       = { read=GetCurEtat};
    __property   HRGN         RGNInvalide   = { read=GetInvalideRgn };
    __property   TCoordonnee  LargBarreGauche = { read=GetLargBarreGauche};

    void __fastcall Modifie( )const                                                                     { DocOwner->Modifie(); /*Owner->Draw( );*/};
    void __fastcall _Invalidate(const HRGN h)const                                                      { DocOwner->_Invalidate( h);};
    void __fastcall _Invalidate(const TRect &rc)const                                                   { DocOwner->_Invalidate( rc);};
    void __fastcall _Invalidate(const int Left, const int Top, const int Right, const int Bottom)const  { DocOwner->_Invalidate( Left,Top,Right,Bottom);};
    void __fastcall _Invalidate()const                                                                  { DocOwner->_Invalidate( );  };
    void __fastcall _Invalidate(const TCoorRect &rc)const                                               { TRect r=rc.RectPixels;  DocOwner->_Invalidate( r);};
    void __fastcall _Invalidate(const TCoordonnee &Left, const TCoordonnee &Top,
                                const TCoordonnee &Right, const TCoordonnee &Bottom)const               { DocOwner->_Invalidate( Left.PixelsX, Top.PixelsY, Right.PixelsX, Bottom.PixelsY);};
    void __fastcall ValidateAll()const                                                                  { DocOwner->ValidateAll( );};
    HRGN __fastcall GetRegionInvalideInRect_ClipIt(const TCoorRect &rc)const                            { TRect r=rc.RectPixels; return DocOwner->GetRegionInvalideInRect_ClipIt( r);};
    HRGN __fastcall GetRegionInvalideInRect_ClipIt(const TRect &rc)const                                { return DocOwner->GetRegionInvalideInRect_ClipIt( rc);};
    HRGN __fastcall GetRegionInvalideInRect_ClipIt(const RECT  &rc)const                                { return DocOwner->GetRegionInvalideInRect_ClipIt( rc);};
    bool __fastcall IsRectInvalideInClip( const RECT  &rc)const                                         { return DocOwner->IsRectInvalideInClip( rc);};
    void __fastcall EffaceRegion( HRGN h)const                                                          { DocOwner->EffaceRegion( h);};
    bool __fastcall IsValidSupport()const                                                               { return DocOwner->IsValidSupport( );};
    TCanvas* __fastcall IsCanvasSupport()const                                                          { return DocOwner->IsCanvasSupport( );};

};
//---------------------------------------------------------------------------
#include "uComposant.h"
//---------------------------------------------------------------------------
class TComposant;
class ETATAPI TEtat : public TMyObject
{
//    friend class TDocument;
    // Fonctions générales
public :
    void __fastcall Enregistre( TFlux *f)const;
//    bool __fastcall Proprietes( );
    void __fastcall Calculs( );
    void __fastcall Draw( );
    void __fastcall DrawEntetePage( );
    void __fastcall DrawPiedPage( );
    void __fastcall DrawEtatSuivant( const AnsiString& FileEtatSuivant, const AnsiString &EtatSuivant, bool ForceReinitialize=false);
    void __fastcall DrawEtatSuivant( TEtat *e, bool ForceReinitialize=false);
    bool __fastcall DrawPages( TObject* Support, TBookmark Bookmark,
                               WORD Etat, WORD Niveau, WORD TypeBande,
                               int PageDebut, int NbPages, int IndiceRepetPremBande);
    void __fastcall CalculNbPages( bool bShowBarre = true);

    __fastcall TEtat( TDocument *DocOwner, const AnsiString &sOleFile);
    __fastcall TEtat( TDocument *Owner, TCoordonnee nTop, TFlux *f = NULL, const AnsiString &TitreVoulu = EmptyStr);
    virtual __fastcall ~TEtat();
    // Caractéristiques de l'état
private :
        // Constructeur et Destructeur appelés uniquement de TDocument
    TDocument*          m_DocOwner;
    bool                m_bPortrait;
    AnsiString          m_Titre;
    type_debutpage      m_DebPage;
    TCoordonnee         m_Top;
    eTypeSQL            m_TypeSQL;
    AnsiString          m_User, m_Password, m_DatabaseName, m_Requete;
    TDataSet*           m_BaseDeDonnee;
    #ifdef _MYSQL
         TZZMySqlQuery*     m_MySqlQuery;
         void __fastcall SetMySqlQuery(TZZMySqlQuery*  b)  {m_MySqlQuery = b;  Modifie();};
    #endif
    TParams*            m_SQLParam;
    TDataSource*        m_DataSource;
    TCalculDeFormules*  m_Formule;
    AnsiString          m_DocPdf;
    int                 m_NumPagePdf;
    short               m_NbCopies;
    bool                m_bReportRupture;
    bool                m_bDebPage;
    unsigned long       m_Tag;
    bool                m_ReinitBDDApresCalculsPage, m_CpEndsInPied;
    EICCurrencyFmt      *m_FormatCurDefaut;
    TCoordonnee         m_EspaceApres;
    AnsiString          m_Filigrane;
    AnsiString          m_GED_Criteres;
    AnsiString          m_NomDocGED;
    bool                m_VersPDF;

    void __fastcall Init( TDocument *DocOwner, TCoordonnee &nTop);
    void __fastcall DebutDeSections( TObject *LstChampAReinitialiser_Ou_BandeLimite);

    TCoordonnee __fastcall GetTop( )const;
    void __fastcall SetSQLParam( TParams* p);
    void __fastcall SetTypeSQL( eTypeSQL b)             {if ( b != m_TypeSQL)  {  m_TypeSQL = b;  Modifie();}};
    void __fastcall SetUser(   const AnsiString& s)     {if ( s != m_User)      { m_User = s;  Modifie();}};
    void __fastcall SetPassword(   const AnsiString& s) {if ( s != m_Password)  { m_Password = s;  Modifie();}};
    void __fastcall SetDatabaseName( const AnsiString& s) {if ( s != m_DatabaseName)  { m_DatabaseName = s;  Modifie();}};
    void __fastcall SetRequete(   const AnsiString& s)  {if ( s != m_Requete)   { m_Requete = s;   Modifie();}};
    void __fastcall SetTitre(   const AnsiString& s);
    void __fastcall SetDebPage( type_debutpage d)       {if ( d != m_DebPage)   { m_DebPage = d;   Modifie();}};
    void __fastcall SetDocPdf(   const AnsiString& s)   {if ( s != m_DocPdf)    { m_DocPdf = s;    _Invalidate();  Modifie();}};
    void __fastcall SetNumPagePdf( int n)               {if ( n != m_NumPagePdf){ m_NumPagePdf = n;_Invalidate();  Modifie();}};
    void __fastcall SetPortrait( bool b);
    void __fastcall SetReportRupture( bool b)           { if( b != m_bReportRupture) { m_bReportRupture = b; _Invalidate();  Modifie();}};
    void __fastcall SetTag( unsigned long i)            { if( i != m_Tag)       { m_Tag = i;Modifie();}};
    TCoordonnee  __fastcall GetHauteur( int bConception = false)const;
    TCoordonnee  __fastcall GetLargeur( )const;
    short    __fastcall GetNbCopies()const              {if( m_EtatAppelant) return m_EtatAppelant->GetNbCopies();                   return  m_NbCopies; };
    void     __fastcall SetNbCopies(short i)            {if( m_EtatAppelant)        m_EtatAppelant->SetNbCopies( i);                 else    m_NbCopies = i; };
    void     __fastcall SetFiligrane( const AnsiString& s) {if ( s != m_Filigrane){ m_Filigrane = s;_Invalidate();  Modifie();}};
    void     __fastcall SetGED_Criteres( const AnsiString& s) {if ( s != m_GED_Criteres){ m_GED_Criteres = s;  Modifie();}};
    void     __fastcall SetNomDocGED( const AnsiString& s) {if ( s != m_NomDocGED){ m_NomDocGED = s;  Modifie();}};
    AnsiString __fastcall GetNomDocGED( )const          { return ( m_NomDocGED.IsEmpty())? Titre : m_NomDocGED; };

    /* Variables d'optimisations */
    WORD m_NiveauBandeBasse;
    TBande *m_BandeDetail;
    bool m_Initialized, m_ResultBdInitialize;

public  :

    __property   AnsiString         Titre        = { read=m_Titre,     write=SetTitre };
    __property   type_debutpage     DebPage      = { read=m_DebPage,   write=SetDebPage };
    __property   bool               Portrait     = { read=m_bPortrait, write=SetPortrait };
    __property   TCoordonnee        Top          = { read=GetTop,      write=m_Top };
    __property   const TCoordonnee  Hauteur      = { read=GetHauteur, index = false};
    __property   const TCoordonnee  HauteurPage  = { read=GetHauteur, index = true};
    __property   const TCoordonnee  Largeur      = { read=GetLargeur};
    __property   eTypeSQL           TypeSQL      = { read=m_TypeSQL,   write=SetTypeSQL };
    __property   AnsiString         User         = { read=m_User,      write=SetUser };
    __property   AnsiString         Password     = { read=m_Password,  write=SetPassword };
    __property   AnsiString         DatabaseName = { read=m_DatabaseName, write=SetDatabaseName };
    __property   AnsiString         Requete      = { read=m_Requete,   write=SetRequete };
    __property   TParams*           SQLParam     = { read=m_SQLParam,  write=SetSQLParam };
    __property   TDataSet*          BaseDeDonnee = { read=m_BaseDeDonnee};
    __property   TDataSource*       DataSource   = { read=m_DataSource};
    #ifdef _MYSQL
    __property   TZZMySqlQuery*     MySqlQuery    = { read=m_MySqlQuery, write=SetMySqlQuery };
    #endif
    __property   TCalculDeFormules* Formule      = { read=m_Formule};
    __property   AnsiString         DocPdf       = { read=m_DocPdf,    write=SetDocPdf };
    __property   int                NumPagePdf   = { read=m_NumPagePdf,write=SetNumPagePdf };
    __property   short              NbCopies     = { read=GetNbCopies,  write=SetNbCopies };
    __property   bool               ReportRupture= { read=m_bReportRupture,write=SetReportRupture };
    __property   bool               bDebPage     = { read=m_bDebPage};
    __property   unsigned long      Tag          = { read=m_Tag,        write=SetTag };
    __property   bool               ReinitBDDApresCalculsPage= { read=m_ReinitBDDApresCalculsPage,write=m_ReinitBDDApresCalculsPage};
    __property   bool               CpEndsInPied = { read=m_CpEndsInPied, write=m_CpEndsInPied};
    __property   EICCurrencyFmt*    FormatCurDefaut = { read=m_FormatCurDefaut, write=m_FormatCurDefaut};
    __property   TCoordonnee        EspaceApres  = { read=m_EspaceApres,write=m_EspaceApres };
    __property   AnsiString         Filigrane    = { read=m_Filigrane,  write=SetFiligrane };
    __property   AnsiString         GED_Criteres = { read=m_GED_Criteres,  write=SetGED_Criteres };
    __property   AnsiString         NomDocGEDSaisi= { read=m_NomDocGED,  write=SetNomDocGED };
    __property   AnsiString         NomDocGED    = { read=GetNomDocGED,  write=SetNomDocGED };
    __property   bool               VersPDF      = { read=m_VersPDF,    write=m_VersPDF};


    bool __fastcall Initialize( bool bShowBarre = true);
    bool __fastcall AImprimer( bool bVerifBd = true);
    void __fastcall UnInitialize( );
    void __fastcall OnDataChange(TObject* Sender, TField* Field);
    void __fastcall InitParamBaseDeDonnee( bool Force);
    void __fastcall SautDePage( TBande* FirstOnNewPage, bool bDebutEffacable, bool bContinue = true);
    void __fastcall ValideDebutDePage( bool bValide);
    void __fastcall FinDePage( TBande* FirstOnNewPage);
    void __fastcall NouvellePage( TBande* FirstOnNewPage, bool bDebutEffacable);
    void __fastcall InitialiseNouvellePage( TBande* FirstOnNewPage, bool bDrawEntete);
    void __fastcall DebutDePage( TBande* FirstOnNewPage, bool bDrawEntete, TBande* LastBdDessinee);
    TCoordonnee __fastcall CalculPlaceVoulueEnBas( const TBande *Bd, bool bTakeBdPrec = false)const;
    void __fastcall InitPrinter( MyCBarre *pBarre);
    void __fastcall ReleasePrinter( );
    // BANDES de l'état
private:
    TListOfBandes *m_LstBandes;
    TCoordonnee  __fastcall GetHauteurEntete()const;
    TCoordonnee  __fastcall GetHauteurPied()const;

public:
    __property TListOfBandes* LstBandes = {read = m_LstBandes};
    TDocument* __fastcall  GetDocOwner()const { return m_DocOwner;};
    TBande* __fastcall GetBandeDetail()const;
    TBande* __fastcall GetBandeSpec( TYPE_BANDE eType)const; // Recherche dans la lst de bande de l'état et celle de + haut niveau
    TBande* __fastcall GetBandeDebColonne()const     { return GetBandeSpec( e_DebutColonne);};
    TBande* __fastcall GetBandeFinColonne()const     { return GetBandeSpec( e_FinColonne);};
    TBande* __fastcall GetBandeReportDebPage()const  { return GetBandeSpec( e_ReportDebDePage);};
    TBande* __fastcall GetBandeReportFinPage()const  { return GetBandeSpec( e_ReportFinDePage);};
    WORD    __fastcall GetNiveauBandeBasse( )const;
    TBande* __fastcall SearchBande( TYPE_BANDE eType)const;

    void __fastcall InsereBande( TYPE_BANDE eType);
    void __fastcall SupprimeBande( TYPE_BANDE eType);

    void __fastcall InsereEnteteEtat( )                                 { InsereBande( e_EnTete); };
    void __fastcall InsereDebutEtat( )                                  { InsereBande( e_Debut); };
    void __fastcall InsereDebutColonne( )                               { InsereBande( e_DebutColonne); };
    void __fastcall InsereFinColonne( )                                 { InsereBande( e_FinColonne); };
    void __fastcall InsereFinEtat( )                                    { InsereBande( e_Fin); };
    void __fastcall InserePiedEtat( )                                   { InsereBande( e_Pied); };
    void __fastcall SupprimeEnteteEtat( )                               { SupprimeBande( e_EnTete); };
    void __fastcall SupprimeDebutEtat( )                                { SupprimeBande( e_Debut); };
    void __fastcall SupprimeDebutColonne( )                             { SupprimeBande( e_DebutColonne); };
    void __fastcall SupprimeFinColonne( )                               { SupprimeBande( e_FinColonne); };
    void __fastcall SupprimeFinEtat( )                                  { SupprimeBande( e_Fin); };
    void __fastcall SupprimePiedEtat( )                                 { SupprimeBande( e_Pied); };

    TBande* __fastcall GetBande( TYPE_BANDE eType, WORD wNiveau)const;
    TBande* __fastcall GetBande( const TCoordonnee &Y)const;
    __property TCoordonnee    HauteurEntete = { read=GetHauteurEntete };
    __property TCoordonnee    HauteurPied   = { read=GetHauteurPied };


    bool __fastcall QuEstCeQuiYaDessous( const TCoordonnee &X, const TCoordonnee &Y, TBande **BandeCourante, TComposant **CpCourant, Type_CoinSelectionne *CoinCourant, bool *bOnEstDansLaMarge)const;
    AnsiString  __fastcall GetChampDB( const AnsiString &ChampDB)const;

    // COMPOSANTS de l'état
private:

public:
    void __fastcall GetComposantsIn( TList* ListeCp, const TCoorRect &rSelection, const TBande* BandeQuiDemande, bool bSelEntier)const;
    TComposant* __fastcall GetComposant( const TCoordonnee &X, const TCoordonnee &Y, Type_CoinSelectionne &CoinCourant)const ;
    TComposant* __fastcall GetComposant( const AnsiString &s)const;
    void        __fastcall GetComposants( enum TypesComposants TypeCp, TStrings *LstCp)const;
    void        __fastcall InvalideComposantsAttacheA( const AnsiString &ChpAttache);
    void        __fastcall NettoieComposantsAttacheA( const AnsiString &ChpAttache);

    void __fastcall OnErrorEvent( const AnsiString &Message);
    bool __fastcall OnVariableEvent(const AnsiString &Variable, TFieldType &Type, AnsiString &Valeur);

private:
//    int            m_AncResolEcran;
    TEtat         *m_EtatAppelant;
    int            m_NumberOfPage, m_NbPageDessinees;
    int            m_CurrentPage;
    TCoordonnee    m_BasDerniereBande;
    TList         *m_LstCpChamp;
    TStringList   *m_LstCpTableau;
    TList         *m_LstCpColonne;
    TList         *m_LstCpLigne;
    TList         *m_LstCpEnCours;
    TList         *m_LstCpExtensibles;
    int            m_NbPageADessiner;
    __int64        m_EtatNiveauType_FirstBandeToDraw;
    int            m_IndiceRepetPremBande;
    TBande        *m_BandeEnCours, *m_DernBandeDessinee;
    short          m_NbBandesSurLaPage;
    TCpChamp      *m_CpChampEnCours;
    bool           m_bColonneEnCours;
    int            m_nbEnreg;
    bool           m_bPremBandeEtat;
    bool           m_bFinPage;
    short          m_Saute2Pages;
    bool           m_ForceSautDePage;
    int            m_NumeroEnVisu;
    int            m_NumeroInOriginalFileName;
    TEtat         *m_EtatSuivant;
    DWORD          m_NiveauTypeBeforeUtil, m_NiveauTypeAfterUtil;
    AnsiString     m_OriginalFileName;
    COle*          m_Ole;
    bool           m_ReportFinPageAffiche;
    bool           m_ForcerMonetaireSaufZeroSignificatif;

    bool                        m_TakeEvForces;
    TOnEtatEventInterne         f_OnDebutEtatForce;
    TOnEtatEventInterne         f_OnFinEtatForce;
    TOnBandeEventInterne        f_OnFirstBandeEtatForce;
    TOnBandeEventInterne        f_OnBandeForce;
    TOnConstBandeEventInterne   f_OnAfterFirstBandeInitForce;
    TOnChampEventInterne        f_OnChampForce;
    TOnTableauEventInterne      f_OnTableauForce;
    TOnSQLParamsEventInterne    f_OnSQLParamsForce;
    TOnEtatEventInterne         f_OnBDInitializedForce;
    TOnErrorEvent               f_OnErrorForce;
    TOnVariableEvent            f_OnVariableForce;

    int      __fastcall GetNbPageADessiner()const                       {if( m_EtatAppelant) return m_EtatAppelant->GetNbPageADessiner();                   return  m_NbPageADessiner; };
    void     __fastcall SetNbPageADessiner(int i)                       {if( m_EtatAppelant)        m_EtatAppelant->SetNbPageADessiner( i);                 else    m_NbPageADessiner = i; };
    int      __fastcall GetNbPageDessinees()const                       {if( m_EtatAppelant) return m_EtatAppelant->GetNbPageDessinees();                   return  m_NbPageDessinees; };
    void     __fastcall SetNbPageDessinees(int i)                       {if( m_EtatAppelant)        m_EtatAppelant->SetNbPageDessinees( i);                 else    m_NbPageDessinees = i; };
    int      __fastcall GetCurrentPage()const                           {if( m_EtatAppelant) return m_EtatAppelant->GetCurrentPage();                       return  m_CurrentPage; };
    void     __fastcall SetCurrentPage(int i)                           {if( m_EtatAppelant)        m_EtatAppelant->SetCurrentPage( i);                     else    m_CurrentPage = i; };
    int      __fastcall GetNumberOfPage()const                          {if( m_EtatAppelant) return m_EtatAppelant->GetNumberOfPage();                      return  m_NumberOfPage; };
    void     __fastcall SetNumberOfPage(int i)                          {if( m_EtatAppelant)        m_EtatAppelant->SetNumberOfPage( i);                    else    m_NumberOfPage = i; };
    __int64  __fastcall GetEtatNiveauType_FirstBandeToDraw()const       {if( m_EtatAppelant) return m_EtatAppelant->GetEtatNiveauType_FirstBandeToDraw();   return  m_EtatNiveauType_FirstBandeToDraw; };
    void     __fastcall SetEtatNiveauType_FirstBandeToDraw(__int64 i)   {if( m_EtatAppelant)        m_EtatAppelant->SetEtatNiveauType_FirstBandeToDraw( i); else    m_EtatNiveauType_FirstBandeToDraw = i; };
    bool     __fastcall GetSaute2Pages()const                           {if( m_EtatAppelant) return m_EtatAppelant->GetSaute2Pages();                       return  m_Saute2Pages; };
    void     __fastcall SetSaute2Pages(bool i)                          {if( m_EtatAppelant)        m_EtatAppelant->SetSaute2Pages( i);                     else    m_Saute2Pages = i; };
    bool     __fastcall GetForceSautDePage()const                       {if( m_EtatAppelant) return m_EtatAppelant->GetForceSautDePage();                   return  m_ForceSautDePage; };
    void     __fastcall SetForceSautDePage(bool i)                      {if( m_EtatAppelant)        m_EtatAppelant->SetForceSautDePage( i);                 else    m_ForceSautDePage = i; };
    TCoordonnee  __fastcall GetBasDerniereBande()const                  {if( m_EtatAppelant) return m_EtatAppelant->GetBasDerniereBande();                  return  m_BasDerniereBande; };
    void     __fastcall SetBasDerniereBande(const TCoordonnee &c)       {if( m_EtatAppelant)        m_EtatAppelant->SetBasDerniereBande( c);                else    m_BasDerniereBande = c; };
    DWORD    __fastcall GetNiveau()const                                {if( m_EtatAppelant) return m_EtatAppelant->GetNiveau()+1;                          return  0; };
    short    __fastcall GetNbBandesSurLaPage()const                     {if( m_EtatAppelant) return m_EtatAppelant->GetNbBandesSurLaPage();                 return  m_NbBandesSurLaPage; };
    void     __fastcall SetNbBandesSurLaPage(short n)                   {if( m_EtatAppelant)        m_EtatAppelant->SetNbBandesSurLaPage( n);               else    m_NbBandesSurLaPage = n; };

public:
    __property int          NbPageADessiner             = {read=GetNbPageADessiner,             write=SetNbPageADessiner};
    __property int          NbPageDessinees             = {read=GetNbPageDessinees,             write=SetNbPageDessinees};
    __property int          CurrentPage                 = {read=GetCurrentPage,                 write=SetCurrentPage};
    __property int          NumberOfPage                = {read=GetNumberOfPage,                write=SetNumberOfPage};
    __property TCoordonnee  BasDerniereBande            = {read=GetBasDerniereBande,            write=SetBasDerniereBande};
    __property bool         Saute2Pages                 = {read=GetSaute2Pages,                 write=SetSaute2Pages};
    __property bool         ForceSautDePage             = {read=GetForceSautDePage,             write=SetForceSautDePage};
    __property __int64      EtatNiveauType_FirstBandeToDraw  = {read=GetEtatNiveauType_FirstBandeToDraw,   write=SetEtatNiveauType_FirstBandeToDraw};
    __property TList*       LstCpChamp                  = {read=m_LstCpChamp};
    __property TStringList *LstCpTableau                = {read=m_LstCpTableau};
    __property TList*       LstCpColonne                = {read=m_LstCpColonne};
    __property TList*       LstCpEnCours                = {read=m_LstCpEnCours};
    __property TList*       LstCpExtensibles            = {read=m_LstCpExtensibles};
    __property TBande*      BandeEnCours                = {read=m_BandeEnCours,                 write=m_BandeEnCours};
    __property TBande*      DernBandeDessinee           = {read=m_DernBandeDessinee,            write=m_DernBandeDessinee};
    __property short        NbBandesSurLaPage           = {read=GetNbBandesSurLaPage,           write=SetNbBandesSurLaPage};
    __property int          IndiceRepetPremBande        = {read=m_IndiceRepetPremBande,         write=m_IndiceRepetPremBande};
    __property TCpChamp*    CpChampEnCours              = {read=m_CpChampEnCours,               write=m_CpChampEnCours};
    __property bool         bColonneEnCours             = {read=m_bColonneEnCours,              write=m_bColonneEnCours};
    __property int          nbEnreg                     = {read=m_nbEnreg};
    __property TEtat*       EtatAppelant                = {read=m_EtatAppelant,                 write=m_EtatAppelant};
    __property DWORD        Niveau                      = {read=GetNiveau};
    __property bool         bPremBandeEtat              = {read=m_bPremBandeEtat,               write=m_bPremBandeEtat};
    __property bool         bFinPage                    = {read=m_bFinPage};
    __property TEtat*       EtatSuivant                 = {read=m_EtatSuivant,                  write=m_EtatSuivant};
    __property int          NumeroEnVisu                = {read=m_NumeroEnVisu,                 write=m_NumeroEnVisu};
    __property DWORD        NiveauTypeBeforeUtil        = {read=m_NiveauTypeBeforeUtil,         write=m_NiveauTypeBeforeUtil};
    __property DWORD        NiveauTypeAfterUtil         = {read=m_NiveauTypeAfterUtil,          write=m_NiveauTypeAfterUtil};
    __property AnsiString   OriginalFileName            = {read=m_OriginalFileName,             write=m_OriginalFileName};
    __property int          NumeroInOriginalFileName    = {read=m_NumeroInOriginalFileName,     write=m_NumeroInOriginalFileName};
    __property bool         TakeEvForces                = {read=m_TakeEvForces,                 write=m_TakeEvForces};
    __property COle*        Ole                         = {read=m_Ole,                          write=m_Ole};
    __property bool         ReportFinPageAffiche        = {read=m_ReportFinPageAffiche,         write=m_ReportFinPageAffiche};
    __property bool         ForcerMonetaireSaufZeroSignificatif        = {read=m_ForcerMonetaireSaufZeroSignificatif, write=m_ForcerMonetaireSaufZeroSignificatif};


    __property TOnEtatEventInterne    OnDebutEtatForce      = {read=f_OnDebutEtatForce     , write=f_OnDebutEtatForce     };
    __property TOnEtatEventInterne    OnFinEtatForce        = {read=f_OnFinEtatForce       , write=f_OnFinEtatForce       };
    __property TOnBandeEventInterne   OnFirstBandeEtatForce = {read=f_OnFirstBandeEtatForce, write=f_OnFirstBandeEtatForce};
    __property TOnBandeEventInterne   OnBandeForce          = {read=f_OnBandeForce         , write=f_OnBandeForce         };
    __property TOnConstBandeEventInterne OnAfterFirstBandeInitForce = {read=f_OnAfterFirstBandeInitForce, write=f_OnAfterFirstBandeInitForce};
    __property TOnChampEventInterne   OnChampForce          = {read=f_OnChampForce         , write=f_OnChampForce         };
    __property TOnTableauEventInterne OnTableauForce        = {read=f_OnTableauForce       , write=f_OnTableauForce       };
    __property TOnSQLParamsEventInterne  OnSQLParamsForce   = {read=f_OnSQLParamsForce     , write=f_OnSQLParamsForce     };
    __property TOnEtatEventInterne    OnBDInitializedForce  = {read=f_OnBDInitializedForce , write=f_OnBDInitializedForce };
    __property TOnErrorEvent          OnErrorForce          = {read=f_OnErrorForce         , write=f_OnErrorForce};
    __property TOnVariableEvent       OnVariableForce       = {read=f_OnVariableForce      , write=f_OnVariableForce};

    void __fastcall Nettoie( );
    void __fastcall ReinitChamp();
};

//---------------------------------------------------------------------------
class ETATAPI TListOfBandes : public TList
{

private:
    bool         m_bRuptureVisible;
    TObject*     m_Owner;
    TList*       m_TrueList;
    __property   Items;

        // Compare renvoie < 0 si Item1 est inférieur à Item2, 0 s'ils sont égaux et > 0 si Item1 est supérieur à Item2.
    TCoordonnee  __fastcall GetTop( )const;
    TCoordonnee  __fastcall GetHauteur( )const;
	TBande* __fastcall Get(int Index)const;
//	void __fastcall Put(int Index, const TBande * Item){ TList::Put(Index, (void*)Item);};
    int __fastcall GetCount()const;
    int __fastcall IndexOf( const TBande *Bande)const;
    TList* __fastcall GetTrueList( )const;
    TDocument*  m_DocOwner;
    TDocument* __fastcall GetDocOwner( )const;
    TEtat*      m_EtatOwner;
    TEtat*     __fastcall GetEtatOwner( )const;
    TBande*    __fastcall GetBandeOwner( )const;

public:
    __fastcall TListOfBandes( TObject *Owner, TFlux *f = NULL);
    virtual __fastcall ~TListOfBandes( );

    void __fastcall Draw( );
    void __fastcall Enregistre( TFlux *f)const;
    void __fastcall Calculs( );

    void __fastcall Copy( const TListOfBandes * lst);
    void __fastcall Add( TYPE_BANDE eType);
    void __fastcall Delete( TYPE_BANDE eType);

    TBande* __fastcall PreviousBande( const TBande *Bande)const;
    TBande* __fastcall NextBande( const TBande *Bande)const;

    TBande* __fastcall SearchBande( TYPE_BANDE eType)const;
    bool __fastcall Included( const TBande *Bande)const;
    TBande* __fastcall LastBande( )const;
    TBande* __fastcall FirstBande( )const;
    TComposant* __fastcall GetCpPrecedentSuivant( bool bPrec, const TBande* Bande)const;

    __property  TCoordonnee  Top     = {read=GetTop};
    __property  TCoordonnee  Hauteur = {read=GetHauteur};

    TBande*     __fastcall GetBande( const TCoordonnee& cY)const;
    void        __fastcall GetComposantsIn( TList* ListeCp, const TCoorRect &rSelection, const TBande* BandeQuiDemande, bool bSelEntier)const;
    TComposant* __fastcall GetComposant( const TCoordonnee &X, const TCoordonnee &Y, Type_CoinSelectionne &CoinCourant)const;
    TComposant* __fastcall GetComposant( const AnsiString &s)const;
    void        __fastcall GetComposants( enum TypesComposants TypeCp, TStrings *LstCp)const;
    void        __fastcall InvalideComposantsAttacheA( const AnsiString &ChpAttache);
    void        __fastcall NettoieComposantsAttacheA( const AnsiString &ChpAttache);
    void        __fastcall GetCpCalc( TList* ListeCpCalcCol, TList* ListeCpCalcLigne, TList* LstCpExtensibles, bool &bCpNbPages)const;

    __property  TDocument* DocOwner         = {read=GetDocOwner};
    __property  TEtat*     EtatOwner        = {read=GetEtatOwner};
    __property  TBande*    BandeOwner       = {read=GetBandeOwner};
	__property  TBande*  Bandes[int Index]  = {read=Get/*, write=Put/*, default*/};
    __property  int      Count              = {read=GetCount};
    __property  bool     bRuptureVisible    = {read=m_bRuptureVisible, write=m_bRuptureVisible};
    void __fastcall Nettoie( );
    void __fastcall RefreshValRupture( );
};


//---------------------------------------------------------------------------
class ETATAPI TBande : public TMyObject
{
//    friend class TListOfBandes;

public : // Fonctions générales
    __fastcall TBande( TListOfBandes *Lst, TYPE_BANDE Type, TFlux *f = NULL);
    virtual __fastcall ~TBande( );
    void __fastcall SetHauteurModifV1_11(const TCoordonnee &H);

    void         __fastcall Enregistre( TFlux *f)const;
    void         __fastcall Draw( );
    void         __fastcall Calculs( );
    TCoordonnee  __fastcall GetTop( )const;
    void         __fastcall Invalidate( );
    void         __fastcall InvalidateAll( );
    AnsiString   __fastcall GetBubble(const TCoordonnee &X, const TCoordonnee &Y)const;
    void         __fastcall RecupereProprietesComposants( TBande *b);

private :
    static const TCoordonnee   ms_margeYTitre;
    TListOfBandes       *m_LstBandes;
    TListOfComposants   *m_LstComposants;

    TListOfBandes       *m_LstBandesOwner;
//    bool                 m_bSautDePageAvant_Old;
    int                  m_NumBandeUtilSuivante;
    int                  m_NumBandeUtilPrecedente;
    bool                 m_bAutoLoop;

      // Définition globale d'une bande
    TCoordonnee  m_Hauteur;
    TCoordonnee  m_HauteurCalc;
    TCoordonnee  m_HauteurForceeMin;
    TCoordonnee  m_HauteurForceeMax;
    TCoordonnee  m_HauteurForcee;
    TYPE_BANDE   m_eType;

    AnsiString   m_FormuleVisible;
    AnsiString   m_ChpRupture;
    AnsiString   m_ValeurChpRupture;
    AnsiString   m_EtatSuivant;
    int          m_NbEnreg, m_IndiceRepetition;
    bool         m_bSautDePageAvant;
    bool         m_bSautDePageApres;
    bool         m_RuptureInterieureAutorisee;
    bool         m_PrisDansCalculColonne;
    void __fastcall SetChpRupture( const AnsiString &ChpRupture) ;

    void __fastcall EraseBkGnd( const TCoordonnee &nTop);
    void __fastcall DessineMarge( const TCoordonnee &nTop);
    void __fastcall DessineLigneSeparation( const TCoordonnee &nTop);
    void __fastcall DrawTitreBande(  const TCoordonnee &nTop);
    void __fastcall SetHauteur( const TCoordonnee &Hauteur);
    void __fastcall SetHauteurForcee( const TCoordonnee &Hauteur);
    void __fastcall SetSautDePageAvant( bool b) {if ( b != m_bSautDePageAvant)  { m_bSautDePageAvant = b;  Modifie();}};
    void __fastcall SetSautDePageApres( bool b) {if ( b != m_bSautDePageApres)  { m_bSautDePageApres = b;  Modifie();}};
    void __fastcall SetNumBandeUtilSuivante( int i) {if ( i != m_NumBandeUtilSuivante)  { m_NumBandeUtilSuivante = i;  Modifie();}};
    void __fastcall SetNumBandeUtilPrecedente( int i) {if ( i != m_NumBandeUtilPrecedente)  { m_NumBandeUtilPrecedente = i;  Modifie();}};
    void __fastcall SetEtatSuivant( const AnsiString &s) {if ( s != m_EtatSuivant)  { m_EtatSuivant = s;  Modifie();}};
    void __fastcall SetFormuleVisible( const AnsiString &s) {if ( s != m_FormuleVisible)  { m_FormuleVisible = s;  Modifie();}};
    void __fastcall SetAutoLoop( bool b);
    void __fastcall SetRuptureInterieureAutorisee( bool b) {if ( b != m_RuptureInterieureAutorisee)  { m_RuptureInterieureAutorisee = b;  Modifie();}};
    AnsiString __fastcall GetTitre( )const;
    TCoordonnee __fastcall GetHauteur( )const;
    WORD __fastcall GetNiveau( )const;
    TBande* __fastcall CalcGetPrevBande( ) const;
    TBande* __fastcall CalcGetNextBande( ) const;
    TDocument*      __fastcall GetDocOwner( )const {return m_LstBandesOwner->DocOwner;};
    TEtat*          __fastcall GetEtatOwner( )const {return LstBandesOwner->EtatOwner;};
    TListOfBandes*  __fastcall GetLstBandesOwner( )const;
    bool            __fastcall GetOwnerDocument()const;
    TField* __fastcall GetFieldRupture();
    bool    __fastcall TestHauteur( const TCoordonnee &cPlaceEnBas, bool &AttentionChpExtensibleSurPageSuivante, bool &bBdToDraw, bool bOnVientChangerUnePage);

    TBande *m_PrevBande;
    TBande *m_NextBande;
    TField *m_FieldRupture;


public :
    bool __fastcall IsInBande( const TCoordonnee &Y)const;

    __property   TDocument         *DocOwner        = { read=GetDocOwner};
    __property   TEtat             *EtatOwner       = { read=GetEtatOwner};
    __property   TListOfBandes     *LstBandesOwner  = { read=GetLstBandesOwner};
    __property   TListOfBandes     *LstBandes       = { read=m_LstBandes};
    __property   TListOfComposants *LstComposants   = { read=m_LstComposants};
    __property   AnsiString         Titre           = { read=GetTitre};
    __property   TYPE_BANDE         Type            = { read=m_eType         };
    __property   WORD               Niveau          = { read=GetNiveau      };
    __property   AnsiString         ChpRupture      = { read=m_ChpRupture,  write=SetChpRupture  };
    __property   AnsiString         ValeurChpRupture  = { read=m_ValeurChpRupture,write=m_ValeurChpRupture};
    __property   TField            *FieldRupture    = { read=GetFieldRupture};
    __property   int                NbEnreg         = { read=m_NbEnreg};
    __property   bool               SautDePageAvant = { read=m_bSautDePageAvant,write=SetSautDePageAvant};
    __property   bool               SautDePageApres = { read=m_bSautDePageApres,write=SetSautDePageApres};
    __property   int                NumBandeUtilSuivante = {read=m_NumBandeUtilSuivante,write=SetNumBandeUtilSuivante};
    __property   int                NumBandeUtilPrecedente = {read=m_NumBandeUtilPrecedente,write=SetNumBandeUtilPrecedente};
    __property   AnsiString         EtatSuivant     = {read=m_EtatSuivant,write=SetEtatSuivant};
    __property   AnsiString         FormuleVisible  = {read=m_FormuleVisible,write=SetFormuleVisible};
    __property   bool               OwnerDocument   = { read=GetOwnerDocument};
    __property   bool               bAutoLoop       = { read=m_bAutoLoop, write= SetAutoLoop};
    __property   bool               RuptureInterieureAutorisee = { read=m_RuptureInterieureAutorisee, write= SetRuptureInterieureAutorisee};
    __property   int                IndiceRepetition = { read=m_IndiceRepetition, write=m_IndiceRepetition};
    __property   bool               PrisDansCalculColonne = { read=m_PrisDansCalculColonne, write=m_PrisDansCalculColonne};

    void __fastcall Nettoie( );
    WORD __fastcall GetNiveauValChange( );
    void __fastcall RefreshValRupture( );

    TComposant* __fastcall GetComposant( const AnsiString &s)const;
    void        __fastcall GetComposants( enum TypesComposants TypeCp, TStrings *LstCp)const;
    void        __fastcall InvalideComposantsAttacheA( const AnsiString &ChpAttache);
    void        __fastcall NettoieComposantsAttacheA( const AnsiString &ChpAttache);
    void __fastcall GetLimitesHauteur( TCoordonnee &Mini, TCoordonnee &Maxi)const;
    void __fastcall ReprendHauteur( const TBande *b);
    void __fastcall GetMarges( TCoorRect &Marge)const;
    void __fastcall GetClipRectLimite( RECT &rc)const;
    void __fastcall GetLimites( TCoorRect &rc/*, bool bWithBarreGauche = false*/);
    TCpChamp*   __fastcall GetCpChamp( const AnsiString &s)const;
    TCpTableau* __fastcall GetCpTableau( const AnsiString &s)const;
    __property   TBande*      PreviousBande = { read=CalcGetPrevBande/*m_PrevBande*/};
    __property   TBande*      NextBande     = { read=CalcGetNextBande/*m_NextBande*/};
    __property   TCoordonnee  Hauteur = { read=GetHauteur, write=SetHauteur};
    __property   TCoordonnee  HauteurForcee = { read=m_HauteurForcee, write=SetHauteurForcee};

    __property   TCoordonnee  Top     = { read=GetTop   };

    bool  __fastcall operator  <  (const TBande &b)const;
    bool  __fastcall operator  >  (const TBande &b)const;
    bool  __fastcall operator  == (const TBande &b)const;
    bool  __fastcall operator  <= (const TBande &b)const { return operator<(b) || operator==(b);};
    bool  __fastcall operator  >= (const TBande &b)const { return operator>(b) || operator==(b);};

    bool  __fastcall operator  < (__int64 EtatNiveauType)const;
    bool  __fastcall operator  > (__int64 EtatNiveauType)const;
    bool  __fastcall operator  == (__int64 EtatNiveauType)const;
    bool  __fastcall operator  != (__int64 EtatNiveauType)const;
    bool  __fastcall operator  <= (__int64 EtatNiveauType)const { return operator<(EtatNiveauType) || operator==(EtatNiveauType);};
    bool  __fastcall operator  >= (__int64 EtatNiveauType)const { return operator>(EtatNiveauType) || operator==(EtatNiveauType);};

    void        __fastcall SupprimeComposant( TComposant *Cp);
    TComposant* __fastcall InsereComposant( Carac_Composant wType, const TCoordonnee &X, const TCoordonnee &Y);
    TComposant* __fastcall InsereTexte(  const TCoordonnee &X,  const TCoordonnee &Y)     { return InsereComposant( Carac_Texte, X, Y); };
    TComposant* __fastcall InsereRectangle(  const TCoordonnee &X,  const TCoordonnee &Y) { return InsereComposant( Carac_Rectangle, X, Y); };
    TComposant* __fastcall InsereEllipse(  const TCoordonnee &X,  const TCoordonnee &Y)   { return InsereComposant( Carac_Ellipse, X, Y); };
    TComposant* __fastcall InsereImage(  const TCoordonnee &X,  const TCoordonnee &Y)     { return InsereComposant( Carac_Image, X, Y); };
    TComposant* __fastcall InsereFleche(  const TCoordonnee &X,  const TCoordonnee &Y)    { return InsereComposant( Carac_Fleche, X, Y); };
    TComposant* __fastcall InsereChamp(  const TCoordonnee &X,  const TCoordonnee &Y)     { return InsereComposant( Carac_Champ, X, Y); };
    TComposant* __fastcall InsereTableau(  const TCoordonnee &X,  const TCoordonnee &Y)   { return InsereComposant( Carac_Tableau, X, Y); };
#if cp_NbTypeCp != 7
    #error "Composant non reconnu"
#endif
};

TDocument* /*PACKAGE*/ ETATAPI __fastcall NewTDocument(const AnsiString& File, const AnsiString& TitreEtatVoulu=EmptyStr);
void       /*PACKAGE*/ ETATAPI __fastcall DeleteTDocument(TDocument* Doc);
TEtat*     /*PACKAGE*/ ETATAPI __fastcall NewTEtatOLE(TDocument* Doc, const AnsiString& File, bool Resize, bool bEntetePied);
TEtat*     /*PACKAGE*/ ETATAPI __fastcall NewTEtat(TDocument* Doc, const AnsiString& File);
void       /*PACKAGE*/ ETATAPI __fastcall DeleteTEtat(TEtat* Etat);

//---------------------------------------------------------------------------
#endif
